package com.linewell.controller;

import com.linewell.entity.UserInfo;
import com.linewell.service.ICommentService;
import com.linewell.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
/**
 * @Title: ssm2
 * @description: 评论管理控制器
 * @author: hyuhuang@linewell.com
 * @since:2018/2/13
 */
@Controller
public class CommentController {

	@Autowired
	private ICommentService commentService;

	/**
	 * @descripition  插入评论
	 * @author hyuhuang@linewell.com
	 * @date 2018/2/27 10:44
	 * @param articleId, content, request
	 * @return com.linewell.utils.Msg
	 */
	@RequestMapping("/insertComment")
	@ResponseBody
	public Msg insertComment(@RequestParam("articleid") long articleId, @RequestParam("content") String content,
							 @RequestParam("userIdByArticle") long userIdByArticle,HttpServletRequest request){
		UserInfo userInfo=(UserInfo)request.getSession().getAttribute("LoginUser");
		return commentService.insertComment(articleId, content,userInfo,userIdByArticle);
	}


    /**
     * @descripition  获得回复文章的留言
     * @author hyuhuang@linewell.com
     * @date 2018/3/23 18:49
     * @param articleId, page
     * @return com.linewell.utils.Msg
     */
	@RequestMapping(value = "/getReply",method = RequestMethod.GET)
	@ResponseBody
	public Msg getComment(@RequestParam("articleId")long articleId,@RequestParam("page")int page,
						  @RequestParam("userId")long userId){
		return commentService.getReply(userId,articleId,page);
	}
	/**
	 * @descripition  获得对自己的评论
	 * @author hyuhuang@linewell.com
	 * @date 2018/3/23 21:35
	 * @param userId, page
	 * @return com.linewell.utils.Msg
	 */
    @RequestMapping(value = "/getCommentByUserId",method = RequestMethod.GET)
    @ResponseBody
    public Msg getCommentByUserId(@RequestParam("userId")long userId,@RequestParam("page") int page){
	    return commentService.getCommentByUserId(userId,page);
    }
	/**
	 * @descripition  删除评论 只有本人能操作
	 * @author hyuhuang@linewell.com
	 * @date 2018/3/28 20:02
	 * @param replyId
	 * @return com.linewell.utils.Msg
	 */
	@RequestMapping(value = "/deleteComment",method = RequestMethod.GET)
	@ResponseBody
	public Msg deleteComment(@RequestParam("replyId")long replyId){
    	return commentService.deleteComment(replyId);
	}
	/**
	 * @descripition  获取文章评论信息
	 * @author hyuhuang@linewell.com
	 * @date 2018/3/28 20:02
	 * @param articleId
	 * @return com.linewell.utils.Msg
	 */
	@RequestMapping(value = "/godComment",method = RequestMethod.GET)
	@ResponseBody
	public Msg godComment(@RequestParam("articleId")long articleId){
		return commentService.godComment(articleId);
	}

	@RequestMapping(value = "/getHotReply",method = RequestMethod.GET)
	@ResponseBody
	public Msg getHotReply(@RequestParam("page") int page){
		return commentService.getHotReply(page);
	}

	/**
	 * @Description  保存回复信息
	 * @author hyuhuang@linewell.com
	 * @date 2018/4/14
	 * @param replyId, commentId, content
	 * @return com.linewell.utils.Msg
	 */
	@RequestMapping(value = "/saveReply",method = RequestMethod.GET)
	@ResponseBody
	public Msg saveReply(@RequestParam("replyFromId")Long replyFromId,
						 @RequestParam("replyToId")Long replyToId,
						 @RequestParam("replyId")Long replyId,
						 @RequestParam("content")String content){
		return commentService.insertReply(replyId,replyFromId,replyToId,content);
	}
}
